	package actions;

	import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;

	import org.apache.struts.action.*;

	//import db.DbException;
	import forms.LoginSubmitForm;
import model.Applicant;
import model.Database;

	public class LogonSubmitAction extends Action {

		public ActionForward execute(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response){

			// Cast the form
			LoginSubmitForm iForm = (LoginSubmitForm) form;
			Applicant applicant = new Applicant();
			
			try {
				if (Database.isValidPassword(iForm.getUsername(), iForm.getPassword())) {
					return mapping.findForward("success");
				}
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			request.setAttribute("Applicant", applicant);

			return mapping.findForward("failure");
		}
	}

